package com.zjp.converter;

import com.zjp.domain.InnerSource;
import com.zjp.domain.InnerTarget;
import com.zjp.domain.Source;
import com.zjp.domain.Target;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

@Mapper
public interface SourceMapper {

    SourceMapper INSTANCE = Mappers.getMapper(SourceMapper.class);

    @Mapping(source = "sourceName", target = "targetName")
    Target toTarget(Source source);

    default InnerTarget innerTarget2InnerSource(InnerSource innerSource) {
        if (innerSource == null) {
            return null;
        }
        InnerTarget innerTarget = new InnerTarget();
        innerTarget.setDeleted(innerSource.getDeleted() == 1);
        innerTarget.setName(innerSource.getName());
        return innerTarget;
    }
}